package com.family.pedigree.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.family.common.utils.StringUtils;
import com.family.pedigree.domain.FamilyLeader;
import com.family.pedigree.mapper.FamilyLeaderMapper;
import com.family.pedigree.service.IFamilyLeaderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 领导简介表 服务实现类
 * </p>
 *
 * @author forever
 * @since 2025-01-13
 */
@Service
public class FamilyLeaderServiceImpl extends ServiceImpl<FamilyLeaderMapper, FamilyLeader> implements IFamilyLeaderService {

    @Override
    public void add(FamilyLeader familyLeader) {
        save(familyLeader.setCreateBy("admin").setUpdateBy("admin"));
    }

    @Override
    public List<FamilyLeader> selectList(FamilyLeader familyLeader) {
        return list(Wrappers.<FamilyLeader>lambdaQuery()
                .eq(familyLeader.getIsNow() != null, FamilyLeader::getIsNow, familyLeader.getIsNow())
                .eq(StringUtils.isNotBlank(familyLeader.getGender()), FamilyLeader::getGender, familyLeader.getGender())
                .like(StringUtils.isNotBlank(familyLeader.getName()), FamilyLeader::getName, familyLeader.getName())
                .like(StringUtils.isNotBlank(familyLeader.getNation()), FamilyLeader::getNation, familyLeader.getNation())
                .like(StringUtils.isNotBlank(familyLeader.getHoldPot()), FamilyLeader::getHoldPot, familyLeader.getHoldPot())
                .orderByDesc(FamilyLeader::getCreateTime));

    }

    /**
     * @param isNow 0现任 1-往任
     */
    @Override
    public List<FamilyLeader> getLeaderByNow(int isNow) {
        return list(Wrappers.<FamilyLeader>lambdaQuery().eq(FamilyLeader::getIsNow, isNow));
    }
}
